using System;
using System.Collections.Generic;
using System.Text;
using Decav.Gatsb.Application;
using Decav.Collections;
using Decav.Transactions;

namespace Decav.Gatsb.ApplicationConsole
{
    public class MyContact
    {
        public MyContact(string name, string email)
        {
            _name = name;
            _email = email;
        }

        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                OnNameChanging(EventArgs.Empty);
                _name = value;
                OnNameChanged(EventArgs.Empty);
            }
        }

        private string _email;

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }


        #region Email Propery Change/Changing Event

        /// <summary>
        /// Event that is raised when the Email property is about to be changed.
        /// </summary>
        [field: NonSerialized]
        public event EventHandler EmailChanging;

        /// <summary>
        /// Event that is raised after the Email property has been changed.
        /// </summary>
        [field: NonSerialized]
        public event EventHandler EmailChanged;

        /// <summary>
        /// Raises the EmailChanging event to event subscribers.
        /// </summary>
        /// <remarks>
        /// Note to inheritors: You must call the base method in order to ensure that the event is raised and clean up
        /// work is properly performed.
        /// </remarks>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnEmailChanging(EventArgs e)
        {
            
            // Invoke the event handlers
            EventHandler handler = EmailChanging;
            if (handler != null)
            {
                handler(this, e);
            }   // if

        }

        /// <summary>
        /// Raises the EmailChanged event to event subscribers and binds new event subscriptions.
        /// </summary>
        /// <remarks>
        /// Note to inheritors: You must call the base method in order to ensure that the event is raised and clean up
        /// work is properly performed.
        /// </remarks>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnEmailChanged(EventArgs e)
        {

            // Invoke the event handlers
            EventHandler handler = EmailChanged;
            if (handler != null)
            {
                handler(this, e);
            }   // if

        }

        #endregion

        #region Name Propery Change/Changing Event

        /// <summary>
        /// Event that is raised when the Name property is about to be changed.
        /// </summary>
        [field: NonSerialized]
        public event EventHandler NameChanging;

        /// <summary>
        /// Event that is raised after the Name property has been changed.
        /// </summary>
        [field: NonSerialized]
        public event EventHandler NameChanged;

        /// <summary>
        /// Raises the NameChanging event to event subscribers.
        /// </summary>
        /// <remarks>
        /// Note to inheritors: You must call the base method in order to ensure that the event is raised and clean up
        /// work is properly performed.
        /// </remarks>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnNameChanging(EventArgs e)
        {
            
            // Invoke the event handlers
            EventHandler handler = NameChanging;
            if (handler != null)
            {
                handler(this, e);
            }   // if

        }

        /// <summary>
        /// Raises the NameChanged event to event subscribers and binds new event subscriptions.
        /// </summary>
        /// <remarks>
        /// Note to inheritors: You must call the base method in order to ensure that the event is raised and clean up
        /// work is properly performed.
        /// </remarks>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnNameChanged(EventArgs e)
        {

            // Invoke the event handlers
            EventHandler handler = NameChanged;
            if (handler != null)
            {
                handler(this, e);
            }   // if

        }

        #endregion
        
    }

    public class MyOtherContact
    {
        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                OnNameChanging(EventArgs.Empty);
                _name = value;
                OnNameChanged(EventArgs.Empty);
            }
        }

        private string _email;

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }



        #region Name Propery Change/Changing Event

        /// <summary>
        /// Event that is raised when the Name property is about to be changed.
        /// </summary>
        [field: NonSerialized]
        public event EventHandler NameChanging;

        /// <summary>
        /// Event that is raised after the Name property has been changed.
        /// </summary>
        [field: NonSerialized]
        public event EventHandler NameChanged;

        /// <summary>
        /// Raises the NameChanging event to event subscribers.
        /// </summary>
        /// <remarks>
        /// Note to inheritors: You must call the base method in order to ensure that the event is raised and clean up
        /// work is properly performed.
        /// </remarks>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnNameChanging(EventArgs e)
        {

            // Invoke the event handlers
            EventHandler handler = NameChanging;
            if (handler != null)
            {
                handler(this, e);
            }   // if

        }

        /// <summary>
        /// Raises the NameChanged event to event subscribers and binds new event subscriptions.
        /// </summary>
        /// <remarks>
        /// Note to inheritors: You must call the base method in order to ensure that the event is raised and clean up
        /// work is properly performed.
        /// </remarks>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnNameChanged(EventArgs e)
        {

            // Invoke the event handlers
            EventHandler handler = NameChanged;
            if (handler != null)
            {
                handler(this, e);
            }   // if

        }

        #endregion

    }

    class Program
    {
        static void Main(string[] args)
        {/*
            MyContact source = new MyContact("Andre", "me@decav.com");
            MyOtherContact target = new MyOtherContact();
            DataBinder binder = new DataBinder(target, new PublicPropertyBindingTargetSelector(false));
            binder.TargetEventAdapter = new EventHandlerDataBindEventAdapter();
            binder.SourceEventAdapter = new EventHandlerDataBindEventAdapter();
            binder.BoundPropertiesSelector = new PublicPropertyBoundPropertiesSelector();
            binder.Bind(source);*/


            MessageService svc = new MessageService();
            Console.WriteLine("Starting up!");
            svc.Start();
            Console.WriteLine("Started");
            Console.ReadLine();
            Console.WriteLine("Shutting Down!");
            svc.Stop();
            Console.WriteLine("Thats all folks!");
            Console.ReadLine();
            //binder.Dispose();
        }
    }
}
